//1. 安装
//2. 导入
const mongoose = require("mongoose");

//3. 连接 mongodb 数据库
mongoose.connect("mongodb://127.0.0.1:27017/h5220707");

//4. 设置回调  on  when 当...时候
mongoose.connection.on("open", () => {
  //5. 声明文档结构对象 
  const MovieSchema = new mongoose.Schema({
    name: String,
    actors: Array,
    releaseYear: Number,
  });

  //6. 创建文档模型对象
  const MovieModel = mongoose.model("movie", MovieSchema);

  //7. 文档操作
  //查询数据   fs.readFile  fs.writeFile
  // MovieModel.findOne({_id: '632e808dadd02b0825688260'}, (err, data) => {
  //   if(err) throw err;
  //   console.log(data);
  //   //
  //   mongoose.connection.close();
  // })

  //批量获取
  MovieModel.find({name: '大话西游'}, (err,data) => {
    if(err) throw err;
    console.log(data);
    mongoose.connection.close();
  });
  
});

/**
 * 场景
 * 1. 搜索结果
 * 2. 商品列表
 * 3. 视频列表
 * 4. 单个视频呈现
 * 5. 文章呈现
 * ...
 */

